package com.atguigu.dw.gmall.realtime.util

import java.util.Properties

import org.apache.commons.lang3.StringUtils

/**
 * description ：通过指定名称读取配置文件工具类
 * author      ：剧情再美终是戏 
 * mail        : 13286520398@163.com
 * date        ：Created in 2020/2/11 17:55
 * modified By ：
 * version:    : 1.0
 */
class PropertiesUtil(val fileName: String) {

  // 通过类加载器加载指定名称的文件流
  private val is = this.getClass.getClassLoader.getResourceAsStream(fileName)

  // 创建配置文件,并加载读取配置文件的流数据
  private val properties = new Properties
  properties.load(is)

  /**
   * 通过指定的key获取指定配置文件的内容
   *
   * @Author 剧情再美终是戏
   * @Date 2020/2/11 18:01
   * @param key
   * @return java.lang.String
   * @Version 1.0
   **/
  def getProperty(key: String): String = {
    if (StringUtils.isBlank(key)) {
      ""
    } else {
      properties.getProperty(key)
    }
  }
}

object PropertiesUtil {
  def apply(fileName: String): PropertiesUtil = new PropertiesUtil(fileName)
}